package com.opmsys.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.opmsys.mapper.AccidentMapper;
import com.opmsys.pojo.dto.AccidentPageDTO;
import com.opmsys.pojo.entity.Accident;
import com.opmsys.result.PageResult;
import com.opmsys.service.AccidentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 描述
 *
 * @datatime:2024-06-17 17:56
 */
@Service
public class AccidentServiceImpl implements AccidentService {


    @Autowired
    AccidentMapper accidentMapper;

    /**
     * 新增事故
     * @param accident
     */
    @Override
    public void add(Accident accident) {
        accidentMapper.insert(accident);
    }

    /**
     * 更新事故
     * @param accident
     */
    @Override
    public void update(Accident accident) {
        accidentMapper.update(accident);
    }

    /**
     * 批量删除
     * @param ids
     */
    @Override
    public void delete(List<Integer> ids) {
        ids.forEach(id->{
            accidentMapper.deleteById(id);
        });
    }

    /**
     * 分页查询事故记录
     * @param accidentPageDTO
     * @return
     */
    @Override
    public PageResult pageQuery(AccidentPageDTO accidentPageDTO) {
        PageHelper.startPage(accidentPageDTO.getPage(),accidentPageDTO.getPageSize());
        Page<Accident> page = accidentMapper.pageQuery(accidentPageDTO);
        return new PageResult(page.getTotal(),page.getResult());
    }
}
